# -*- coding: utf-8 -*-
#用于规定字符编码，想要中文正常最好就加上这句

import os.path
import tornado.auth
import tornado.escape
import tornado.httpserver
import tornado.ioloop
import tornado.options
from tornado.options import define, options
from tornado.template import *
import tornado.autoreload


# import pymysql
# pymysql.install_as_MySQLdb()
# from extends import matchdb

# 这里是导入MongoDB
import pymongo

from route import *

# 定义监听的端口，随便挑个喜欢的数字吧
define("port", default=8002, help="run on the given port", type=int)
define("debug", default=False, help="set debug true", type=bool)


class Application(tornado.web.Application):
    def __init__(self):
        handlers = HANDLERS
        settings = dict(
            template_path=TEMPLATE_PATH,
            static_path=STATIC_PATH,
            xsrf_cookies=True,
            cookie_secret="MYTEST",
            debug=options.debug,
            login_url="/user/login/"
        )
        # db = matchdb.Connection("127.0.0.1:3306", "test", user="root", password="123")


        # 以下是我在不能用torndb的情况下  用的pymongo  以上是我刚测试的
        tornado.web.Application.__init__(self, handlers, **settings)
        self.db = pymongo.MongoClient("localhost").matchpress


def main():
    tornado.options.parse_command_line()
    http_server = tornado.httpserver.HTTPServer(Application())
    http_server.listen(options.port)
    tornado.ioloop.IOLoop.instance().start()
    tornado.autoreload.start()



if __name__ == "__main__":
    main()